|
E.g. given syntax C -> A | b c A -> d | b e If you're parsing non-terminal C and the next token is 'b', you don't know whether it's the first or second alternative of C since they both can start with b. To discover whether a grammar has a context clash: For each non-terminal, N, with multiple alternatives, look at the first symbol of each alternative's right-hand side, call it s. If s is the empty string, then find the set FOLLOWER(N) otherwise find the set FIRST*(s). If any of the sets for N's alternatives intersect then there will be a context clash when parsing N. If the next input symbol is one of those in the intersection of two sets then you won't know which of the alternatives applies. FIRST(s) is the set of symbols with which s can start, including s itself. If s is a non-terminal then FIRST(s) also includes the fir スポンサード リンク
|